copyToStruct

Copy the values of the Redis variables into a structure.

The names of the redis variables to be used are the names of the members in snake_case with optional prefix.

If T is a structure:

struct Foo {
  int fooName;
}

Then copyToStruct copies the value of the variable <prefix>foo_name to foo.fooName

void
copyToStruct
(
T
)
(
Redis redis
,
ref T target
,
string prefix
)

Parameters

redis Redis

Database from which to read the variables

target T

Structure that receives the values

prefix string

Prefix to be added to the variable names

Examples

Redis redis = new Redis("localhost", 6379);
redis.send("SELECT", 1);
redis.send("FLUSHDB");
redis.set!string("cu_condition", "aa");
redis.set!string("cu_logger_name", "DD");
redis.set!bool("cu_visible", true);
redis.set!int("cu_no_of_iteration", 42);
redis.set!double("cu_duration", 19.64);

struct DummyData {
   string condition;
   string loggerName;
   int noOfIteration;
   double duration;
   bool visible;
   string[] lists;
}

DummyData dummy;
redis.copyToStruct(dummy, "cu_");
assert(dummy.condition == "aa");
assert(dummy.loggerName == "DD");
assert(dummy.noOfIteration == 42);
assert(dummy.duration == 19.64);
assert(dummy.lists.length == 0);

Meta